#include "dspSimulator/instruction/SPLOOPD.h"

namespace dspsimulator {

    std::string SPLOOPD::to_string() const {
        return get_standard_condition(m_creg_z) + m_name + " " + std::to_string(m_ii);
    }

    std::shared_ptr<DspInstruction> SPLOOPD::decode_standard_instruction(const std::shared_ptr<DspInstructionInfo> &dsp_instruction_info) {
        std::shared_ptr<SPLOOPD> sploopd;
        std::bitset<32> &data = dsp_instruction_info->m_standard_bits;
        if (common::check_bits<21>(data, 0b000001110100000000000, 2) &&
            exist_standard_condition(common::extract_bits<4>(data, 28))) {
            sploopd = std::make_shared<SPLOOPD>(dsp_instruction_info->address(), 4);
            sploopd->m_creg_z = common::extract_bits<4>(data, 28);
            sploopd->m_ii = common::extract_bits<5>(data, 23).to_ulong() + 1;
            sploopd->m_p = data[0];
        }
        return sploopd;
    }

    std::shared_ptr<DspInstruction> SPLOOPD::decode_compact_instruction(const std::shared_ptr<DspInstructionInfo> &dsp_instruction_info) {
        return nullptr;
    }
}